<!-- 修改收货地址 -->
<template>
  <u-popup v-model="show" mode="bottom" border-radius="24" @maskClick="_close()">
    <view class="position: relative;"> 
      <u-icon name="close" color="#C8C9CC" style="position: absolute;right:0;top:0;padding:32rpx;" @click="_close()" />
      <view class="headTitle tc fw6 fz-16">修改收货地址</view>
      <view class="u-m-b-30" style="height:50vh;">
        <u-field
          label-width="180"
          v-model="postParams.receiveName"
          label="姓名："
          :placeholder="editObj.receiveName"
          :border-bottom="false"
          :clearable="false"
        >
        </u-field>
        <u-field
          label-width="180"
          v-model="postParams.receiveMobile"
          label="手机号："
          :placeholder="editObj.receiveMobile"
          :border-bottom="false"
          :clearable="false"
        >
        </u-field>
          <u-field
          label-width="180"
          v-model="postParams.receiveAddress"
          type="textarea"
          label="收货地址："
          :placeholder="editObj.receiveAddress"
          :border-bottom="false"
          :clearable="false"
        >
        </u-field>
      </view>
      <view class="themeBgColor configBtn fz-16" @click="_configEdit">确认修改</view>
      <view class="safe-bottom"></view>
    </view>
  </u-popup>
</template>
<script>
import orderApi from "@/api/orderApi.js";

export default {
  props: {
    show: {type: Boolean, default: false},
    editObj: {type: Object, default: {}}
  },
  watch: {
    show(nval){
      if(nval){ // 初始赋值
        this.postParams.orderAllId = this.editObj.orderAllId
        this.postParams.receiveName = this.editObj.receiveName
        this.postParams.receiveMobile = this.editObj.receiveMobile
        this.postParams.receiveAddress = this.editObj.receiveAddress
      }
    }
  },
  data () {
    return {
      postParams: {
        orderAllId: '',
        receiveName: '',
        receiveMobile: '',
        receiveAddress: ''
      }
    }
  },
  methods:{
    // 确认修改
    _configEdit(){ // 为空默认赋值
      this.postParams.orderAllId = this.editObj.orderAllId
      this.postParams.receiveName = this.postParams.receiveName || this.editObj.receiveName
      this.postParams.receiveMobile = this.postParams.receiveMobile || this.editObj.receiveMobile
      this.postParams.receiveAddress = this.postParams.receiveAddress || this.editObj.receiveAddress
      orderApi.updateReceiveInfo(this.postParams).then(res=>{
        this.$emit('editAddress', this.postParams)
        this._close()
        uni.showToast({
          title: '修改成功',
          icon: 'none'
        });
      })
    },
    _close(){
      Object.assign(this.$data.postParams, this.$options.data().postParams)
      this.$emit('close')
    }
  }
}
</script>
<style scoped>
.headTitle{
  line-height: 96rpx;
  border-bottom: solid 1px #E5E5E5;
}
.configBtn{
  line-height: 96rpx;
  text-align: center;
  color: #FFF;
}
</style>